package com.example.annolog.config;

import com.example.annolog.interceptor.LogInterceptorAnno;
import com.example.annolog.interceptor.LogInterceptorUrL;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig  implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) { //step3:注册Interceptor
        // 拦截所有请求，通过判断是否有 @LoginRequired 注解 决定是否需要登录
        registry.addInterceptor(new LogInterceptorAnno()).addPathPatterns("/**");//注册以后才能触发aop
       registry.addInterceptor(LogInterceptorUrL()).addPathPatterns("/**");
    }

    @Bean
    public LogInterceptorAnno LogInterceptorAnno() {
        return new LogInterceptorAnno();
    }


    @Bean
    public LogInterceptorUrL LogInterceptorUrL() {
        return new LogInterceptorUrL();
    }
}

